<template>
  <div  class="wrapper">
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '15px' }" />
    <div style="height:150px">
      <FormPanel
        ref="from"
        :list="baseInfo"
        :cols="3"
        formType="show"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
      />
    </div>

    <BreakSpace label="备件列表信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      ref="tablePeij"
      :columns="partColumns"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columnsChange"
      :fetchapi="fetchApi"
      :params="fetchParams"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDrawer('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryPartBaseInfo } from '@/api/partsmanage/financialManagement/invoice/index';
export default {
  name: 'invoiceDetail',
  mixins: [dictionary],
  props:{
    params: {
      type: Object,
      required: true,
      default: () => {}
    },
  },
  data() {
    return {
      baseInfo : this.initBaseInfo(),
      partColumns: this.initPartInfoColumn(),
      fetchApi: queryPartBaseInfo,
      fetchParams: {xhrAbort: true},
    }
  },
  created() {
    this.init(this.params)
    let dictArr = this.createDictList('3024');
    dictArr.forEach(dict =>{
      dict.value = dict.value+"";
    })
    this.baseInfo.find(x => x.fieldName == 'btyslx').itemList =dictArr;
  },
  methods: {
    init(data) {
      //1.初始化基本信息
      this.baseInfo.forEach(x => {
        x.initialValue = data[x.fieldName];
      });
      //2.查询备件列表信息
      // this.fetchParams = Object.assign({},{"bsysdh":data.bsysdh});
      this.fetchParams = Object.assign({},data);
      // queryPartBaseInfo({"bsysdh":data.bsysdh}).then(res =>{
      //   console.log(res);
      // });
    },
    columnsChange(rows){

    },
    closeDrawer(val){
      this.$emit('close')
    },
    initBaseInfo() {
      return [
        {
          type: 'INPUT',
          label: '服务商代码',
          fieldName: 'dealerCode',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '服务商名称',
          fieldName: 'dealerName',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '备件订单号',
          fieldName: 'xsddhm',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '交货单号',
          fieldName: 'bsysdh',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '发运方式',
          fieldName: 'btyslx',
          placeholder: '',
          itemList:[],
          disabled: true
        },
        {
          type: 'DATE',
          label: '发运日期',
          fieldName: 'bsfyrq',
          format: 'yyyy-MM-dd',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物流公司',
          fieldName: 'wsName',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物流单号',
          fieldName: 'traceNo',
          placeholder: '',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'DATE',
          label: '签收日期',
          fieldName: 'bsqcrq',
          placeholder: '请输入',
          format: 'yyyy-MM-dd',
          initialValue: '',
          disabled: true,
        }
      ]
    },
    initPartInfoColumn() {
      return [
        {title: '序号',dataIndex: 'index',width: 80,sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        { title: '是否开票', dataIndex: 'whetherInvoice', sorter: true , dictItems:this.createDictList('1004'),},
        { title: '备件代码', dataIndex: 'bjxmbh', sorter: true },
        { title: '备件名称', dataIndex: 'bjzwmc', sorter: true },
        { title: '出库数量', dataIndex: 'bsfysl', sorter: true },
        { title: '出库金额', dataIndex: 'bsfyje', sorter: true , numberFormat: true}
      ]
    },
    
  }
}
</script>
